package com.crawler58.entity;

import java.applet.Applet;
import java.awt.Frame;
import java.awt.Graphics;

abstract class Shapes{
	protected int x,y,k;
	protected double m;
	public Shapes(int x,int y,int k,double m){
		this.x=x;    this.y=y;
		this.k=k;    this.m=m;
	}
	abstract public double getArea();
	abstract public double getPerimeter();
}

class Rect extends Shapes{
	public double getArea(){
		return(k*m);
	}
	public double getPerimeter(){
		return(2*k+2*m);
	}
	public Rect(int x,int y,int width,int height){
		super(x,y,width,height);
	}
}

class Triangle extends Shapes{
	public double getArea(){
		return(Math.sqrt(m*(m-k)*(m-x)*(m-y)));
	}
	public double getPerimeter(){
		return(x+y+k);
	}
	public Triangle(int baseA,int baseB,int baseC){
		super(baseA,baseB,baseC,0);
		m=(baseA+baseB+baseC)/2.0;
	}
}

class Circle extends Shapes{
	public Circle(int x,int y,int width){
		super(x,y,width,width/2.0);
	}

	@Override
	public double getArea() {
		// TODO Auto-generated method stub
		return m*m*Math.PI;
	}

	@Override
	public double getPerimeter() {
		// TODO Auto-generated method stub
		return 2*Math.PI*m;
	}
}


public class RunShape extends Applet{
	Rect rect =new Rect(5,15,25,25);
	Triangle tri=new Triangle(5,5,8);
	Circle cir=new Circle(13,90,25);
	
	private void drawArea(Graphics g,Shapes s,int a,int b){
		g.drawString(s.getClass().getName()+" "+s.getArea()+" ",a,b);
	}
	private void drawPerimeter(Graphics g,Shapes s,int a,int b){
		g.drawString(s.getClass().getName()+"  "+s.getPerimeter()+" ",a,b);
	}
	/*public RunShape(){
		setVisible(true);
		setBounds(500,500,500,500);
		
	}*/
	public void paint(Graphics g){
		g.drawRect(rect.x, rect.y, rect.k, (int)rect.m);
		
		//g.drawString(""+rect.getArea(),50,35);
		drawArea(g,rect,50,35);
		//g.drawString(""+rect.getPerimeter(),50,55);
		drawPerimeter(g,rect,50,55);
		
		//g.drawString(""+tri.getArea(),50,75);
		drawArea(g,tri,50,75);
		//g.drawString(""+tri.getPerimeter(),50,95);
		drawPerimeter(g,tri,50,95);
		
		g.drawOval(cir.x-(int)cir.k/2,cir.y-(int)cir.k/2,cir.k,cir.k);
		
		//g.drawString(""+cir.getArea(),50,115);
		drawArea(g,cir,50,115);
		//g.drawString(""+cir.getPerimeter(),50,135);
		drawPerimeter(g,cir,50,135);
		
	}
	
	/*public static void main(String args[]){
		RunShape r=new RunShape();
	
	}*/

}
